package com.szxy.example;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.RowRenderData;
import com.szxy.domain.InternalElectricityMarketAnalysisReportData;
import com.szxy.plugin.AreaIncrementTablePolicy;
import com.szxy.plugin.OneCommonTablePolicy;
import com.szxy.plugin.SelfPowerMarketTablePolicy;
import com.szxy.plugin.TwoCommonTablePolicy;
import com.szxy.poitl.PoitlMain;
import com.szxy.utils.RenderDataToWordUtil;

import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: zwz
 * @Date:2020/7/27 16:57
 * @Description:com.szxy.netst
 * @Version:1.0
 **/
public class InternalElectrictyMarketAnalysisReportMain {


    /**
     * 文件名
     */
    public static final String FILE_NAME = "HuibeiElectricReportInternal.docx";
    /**
     * 文件完整路径d
     */
    public static final String path = PoitlMain.class.getClassLoader().getResource(FILE_NAME).getPath();

    /**
     * 数据
     */
    public static InternalElectricityMarketAnalysisReportData datas = new InternalElectricityMarketAnalysisReportData();

    /**
     * 存储渲染数据
     */
    public static Map allDataMap = new HashMap<String, Object>(200);

    /**
     * 数据准备
     */
    public static void before() {

        // 全社会电量
        List<RowRenderData> allSocailValList = RenderDataToWordUtil
                .getRowRenderData(RenderDataToWordUtil.getDataFromDb(96), 7);
        // 购网
        List<RowRenderData> buyPowerValList = RenderDataToWordUtil
                .getRowRenderData(RenderDataToWordUtil.getDataFromDb(36), 13);
        //售电
        List<RowRenderData> sellPowerValList = RenderDataToWordUtil
                .getRowRenderData(RenderDataToWordUtil.getDataFromDb(64), 9);
        //自发自用与市场占有率情况
        List<RowRenderData> selfPowerMarketList = RenderDataToWordUtil
                .getRowRenderData0(RenderDataToWordUtil.getDataFromDb(64), 8);
        //地区增量（变化的）
        List<RowRenderData> areaIncrementMarketList = RenderDataToWordUtil
                .getRowRenderData0AndNo(RenderDataToWordUtil.getDataFromDb(128), 8);
        // 地区存量(多表头)
        List<RowRenderData> areaStockMarketList = RenderDataToWordUtil
                .getRowRenderData2(RenderDataToWordUtil.getDataFromDb(366), 8);
        // 淮北矿业集团
        List<RowRenderData> HuaiMiningGroupList = RenderDataToWordUtil
                .getRowRenderData23(RenderDataToWordUtil.getDataFromDb(96), 7);
        // 皖北煤电集团
        List<RowRenderData> WanbeiCoalAndAElectricity = RenderDataToWordUtil
                .getRowRenderData23(RenderDataToWordUtil.getDataFromDb(40), 7);

        datas.setBuyPowerData(buyPowerValList);
        datas.setSellPowerData(sellPowerValList);
        datas.setAllSocialPowerData(allSocailValList);
        datas.setAreaIncrementMarketData(areaIncrementMarketList);
        datas.setSelfPowerMarketData(selfPowerMarketList);
        datas.setAreaStockMarketData(areaStockMarketList);
        datas.setHuaiMiningGroupUserData(HuaiMiningGroupList);
        datas.setWanbeiCoalAndElectricityUserData(WanbeiCoalAndAElectricity);

        allDataMap.putAll(new HashMap<String, String>() {
            {
                put("month", "5");
                put("year", "2020");
            }
        });
        allDataMap.put("all_social", allSocailValList);
    }

    /**
     * 初始化
     */
    public static void init() throws Exception {
        // 声明配置
        Configure config = Configure.newBuilder()
                .customPolicy("all_social", new TwoCommonTablePolicy())
                .customPolicy("buy_power", new OneCommonTablePolicy())
                .customPolicy("sell_power", new TwoCommonTablePolicy())
                .customPolicy("self_power_market", new SelfPowerMarketTablePolicy())
                .customPolicy("area_increment_market", new AreaIncrementTablePolicy())
//                .customPolicy("area_stock_market", new ThreeCommonTablePolicy())
//                .customPolicy("Huai_Mining_Group", new OneCommonTablePolicy())
//                .customPolicy("Wanbei_Coal_and_Electricity", new OneCommonTablePolicy())
                .build();
        // 核心 API
        XWPFTemplate template = XWPFTemplate.compile(path, config).render(allDataMap);
        // 输出
        FileOutputStream out = new FileOutputStream("D:\\desktop\\internal.docx");
        template.write(out);
        out.flush();
        out.close();
        template.close();
    }


    /**
     * 测试
     *
     * @param args
     */
    public static void main(String[] args) throws Exception {
        before();
        init();
    }

}
